<?php
$name = getInputArray("name", $params,'');
$validate = getInputArray("validate", $params,'');
$id = getInputArray("id", $params,str_replace(".","",str_replace(" ","",microtime())));
$required = getInputArray("required", $params,false);
$title = getInputArray("title", $params,"");
if($title != ""){
	$title = " ,buttonText:'".$title."'";
}
$requiredString = "false";
if($required){
	$requiredString = "true";
}

$text = getInputArray("text", $params,'');
$value = getInputArray("value", $params,'');
if(!$value){
	$value = $text;
}else{
	if (is_numeric($value)){
		$value = date(langEcho("datetimeformat"),$value);
	}		
}
$labelid = str_replace(".","",str_replace(" ","",microtime()));
$messageRequired = getInputArray("messageRequired", $params,langEcho("messageRequired"));
$messageValidate = getInputArray("messageValidate", $params,langEcho("messageValidateDate"));


?>
 <div class="datePicker datetimePicker">
<?php
echo "<input class='dateFormatDiv rounded' type='text' "; 
if ($name != "") echo " name='" . $name ."' ";
 
if ($id != "") echo " id='" . $id ."' ";

$onfocus = "";
$onblur = "";
if($text != ''){
	$onfocus .= "cleanValue('$id','$text');";
	$onblur .= "setValue('$id','$text');";
}

if($onfocus != ''){
	echo " onfocus=\"$onfocus\" ";
}

$onblur .= " setTimeout('validate_date(\'$id\', " . $requiredString . ", \'" . $labelid . "\',\'".$messageRequired."\',\'".$messageValidate."\', \'$text\')',100);"; 
if($onblur != ''){
	echo "onblur=\"$onblur\"";
}

if ($value != "") echo " value='" . $value ."' ";

echo "/><div class='validateTextbox' id='".$labelid."' ></div>";
//echo "<div class='dateFormatDiv'>".langEcho("dateFormat")."</div>";
	echo "<div class='clearFloat'></div>";
echo '<script type="text/javascript">';



echo "$( '#$id' ).datetimepicker({timeFormat: 'h:m', dateFormat: '". langEcho("dateformat:javascript"). "',changeYear:true,changeMonth:true,yearRange: '1900:+10',showOn: 'both',buttonImage: '" . WWWROOT . "/images/calendar.gif',closeText:'".langEcho("done")."', currentText:'".langEcho("now")."', timeText:'".langEcho("time")."', hourText:'".langEcho("hour")."', minuteText:'".langEcho("minute")."',buttonImageOnly: true".$title."});";
if($validate != ''){
echo "registerValidation('$validate', '$id',$requiredString, 'date', '$labelid', '$messageRequired', '$messageValidate','$text');";
}
echo '</script>';
?>
</div>